<template>
  <div>
      <div class="Top">
                      <el-form :inline="true" :model="form" class="demo-form-inline" ref="form" v-if="show">
                <el-form-item label="货品编码" prop="number">
                    <el-input v-model="form.number" placeholder="请输入货品编码"></el-input>
                </el-form-item>
                <el-form-item label="货品名称" prop="name">
                    <el-input v-model="form.name" placeholder="请输入货品名称"></el-input>
                </el-form-item>
                <el-form-item label="所属客户" prop="belongName">
                    <el-input placeholder="请输入所属客户" v-model="form.belongName" :disabled="true">
                        <el-button slot="append" @click="getData">选择</el-button>
                    </el-input>
                </el-form-item>
                                <el-form-item label="所属仓库" prop="wId">
                    <el-select v-model="form.wId" placeholder="请选择所属仓库">
                        <el-option v-for="item in option" :key="item.cId" :label="item.name" :value="item.cId"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit" icon="el-icon-search">搜索</el-button>
                    <el-button @click="Reset('form')" icon="el-icon-refresh">重置</el-button>
                </el-form-item>
            </el-form>
      </div>

 <div class="Newexportsearchrefresh">
                <div class="Addexport">
       <el-button type="warning" plain icon="el-icon-download" >导出</el-button>
                </div>
      <div class="Searchrefresh">
                    <el-tooltip placement="top">
                        <div slot="content">{{ disabled ? '显示搜索' : '隐藏搜索' }}</div>
                        <el-button icon="el-icon-search" circle @click="Showorhide()"> </el-button>
                    </el-tooltip>
                    <el-tooltip content="刷新" placement="top">
                        <el-button icon="el-icon-refresh-left" circle @click="Reset()"></el-button>
                    </el-tooltip>
                </div>
      </div>
      <!-- 数据 -->
       <el-table :data="tableData" style="width: 100%">
            <el-table-column type="index" label="序号" width="120" align="center"> </el-table-column>
            <el-table-column prop="number" label="货品编号" width="100" align="center"> </el-table-column>
            <el-table-column prop="name" label="货品名称" align="center"> </el-table-column>
            <el-table-column prop="belongName" label="所属客户" align="center"> </el-table-column>
            <el-table-column prop="stock" label="库存数量" align="center"> 
                <template slot-scope="scope">
{{scope.row.stock==1? '组合商品' :scope.row.stock}}
                </template>
            </el-table-column>
            <el-table-column prop="category" label="货品类别" align="center"> </el-table-column>
            <el-table-column prop="code" label="条形码" align="center"> </el-table-column>
            <el-table-column prop="brand" label="品牌" align="center"> </el-table-column>
            <el-table-column prop="spec" label="商品规格" align="center"> </el-table-column>
            <el-table-column prop="validity" label="保质期" align="center"> </el-table-column>
        </el-table>
        <div class="block">
                <el-pagination
                style="float:right;"
            background
            v-if="hide"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="form.pageNum"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="form.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                >
                </el-pagination>
            </div>
        <!-- 所属客户 -->
        <el-dialog title="归属仓储客户选择" :visible.sync="dialogTableVisible" width="70%">
            <el-table :data="gridData" style="width: 1080px">
                <el-table-column property="name" label="名称" width="150" align="center"></el-table-column>
                <el-table-column property="address" label="地址" width="200" align="center"></el-table-column>
                <el-table-column property="contacts" label="联系人" align="center"></el-table-column>
                <el-table-column property="callNumber" label="电话" align="center"></el-table-column>
                <el-table-column property="fax" label="传真" align="center"></el-table-column>
                <el-table-column property="phone" label="手机" align="center"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="handleEdit(scope.row.name, scope.row.cId)">选择</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 所属客户弹窗分页 -->
            <div class="block">
                <el-pagination
                style="float:right;"
            background
            v-if="hid"
                    @size-change="handleSizeChang"
                    @current-change="handleCurrentChang"
                    :current-page="pagi.pageNum"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="pagi.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pagi.total"
                >
                </el-pagination>
            </div>
        </el-dialog>
  </div>
</template>

<script>
import { customer,Itemaddition} from '@/api/user';
export default {
data() {
    return {
        // 搜索框
        form:{
            pageNum: 1,
            pageSize: 10,
        },
        // 所属仓库
        option: [],
        // 所属客户
            gridData: [],
                        dialogTableVisible: false,
            // 所属客户分页
             pagi: {
                pageNum: 1,
                pageSize: 10,
                total: undefined
            },
            // 显示隐藏
            disabled: false,
            show: true,
            // 页面数据
            tableData:[],
            // 总条目数
            total:undefined,
            hide:false,
            hid:false
            
    }
},
methods:{
    // 搜索
    onSubmit(){
        Itemaddition(this.form).then((ref)=>{
            console.log(ref);
            this.tableData = ref.rows
            this.total = ref.total
            if(ref.rows == ''){
                this.hide= false
            }else{
                this.hide = true
            }
        })
    },
    // 重置
    Reset(formName){
this.$refs.form.resetFields();
this.onSubmit()
    },
            // 送货仓库
        Deliverywarehouse() {
            customer().then((ref) => {
                this.option = ref.rows;
            });
        },
        // 所属客户
                getData() {
            this.dialogTableVisible = true;
            customer(this.pagi).then((ref) => {
                (this.gridData = ref.rows), (this.pagi.total = ref.total);
                if(ref.rows){
                    this.hid = true
                }else{
                    this.hid = false
                }
            });
        },
        // 所属客户选择框
                handleEdit(name, cId) {
            this.dialogTableVisible = false;
            this.form.belongName = name;
            this.form.cId = cId;
        },
          // 所属客户分页
        handleSizeChang(val) {
            this.pagi.pageSize = Number(val);
            this.getData();
        },
        // 所属客户分页（页数）
        handleCurrentChang(val) {
            this.pagi.pageNum = Number(val);
            this.getData();
        },
                handleSizeChange(val) {
            this.form.pageSize = Number(val);
            this.onSubmit();
        },
        // 所属客户分页（页数）
        handleCurrentChange(val) {
            this.form.pageNum = Number(val);
            this.onSubmit();
        },

// 搜索结束
// 中间部分
// 数据显示隐藏
        Showorhide() {
            (this.show = !this.show), (this.disabled = !this.disabled);
        },
},
mounted(){
    this.Deliverywarehouse()
    this.onSubmit()
}
}
</script>

<style lang="less" scoped>
.Newexportsearchrefresh {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}
.Addexport /deep/ .el-button {
    widows: 70px !important;
}
/deep/.el-form--inline .el-form-item__label{
    font-weight: 700 !important;
}
.block{
    height: 20px;
    margin-top: 10px;
}
</style>